home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-25 | 6.6 KB | 222 lines | [TEXT/PJMM] |
- { Tools Plus Tutorial - - Editing Fields }
-
- { NOTE: }
- { The MWERKS compiler directived ($IFC MWERKS) indicates code that is compiled only by }
- { the CodeWarrior compiler. THINK Pascal and Metrowerks CodeWarrior Pascal have }
- { _slight_ differences, and this compiler directive lets you use one source for both compilers. }
- { You can remove the code that does not pertain to your compiler. }
-
-
- program Tutorial;
- uses
- {$IFC MWERKS}
- Dialogs, Fonts, Processes, SegLoad, TextEdit, ToolsPlus, Windows;
- {$ELSEC}
- ToolsPlus;
- {$ENDC}
-
-
- const
- { Menu constants to make code more readable…}
- ApplMenu = 0;
- FileMenu = 1;
- EditMenu = 2;
-
- { 'To Field' and 'From Field' buttons…}
- bToField = 1;
- bFromField = 2;
-
- type
- Str30 = string[30];
- Str30Ptr = ^Str30;
- Str30Handle = ^Str30Ptr; {Handle to 30-character editing field}
-
-
- var
- Poll: TPPollRecord; {Polling record to retrieve event information}
- ExitTheDemo: boolean; {Should the demo terminate?}
-
- hField1: Str30Handle; {Handle to 1st editing field's 30-char string }
- hField2, hField3: StringHandle; {Handles to 2nd and 3rd editing fields' 255-char string }
- Field: integer; {Field number }
- EditString: Str255; {Field's text }
- theButton: integer; {Button number clicked in an alert }
-
-
-
-
-
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - }
- procedure ProcessMenuSelection;
- const
- NewItem = 1;
- OpenItem = 2;
- CloseItem = 3;
- QuitItem = 5;
- var
- theButton: integer;
- begin
-
- case Poll.Menu.Num of
- ApplMenu: {Apple menu's 'About…' item}
- theButton := AlertBox(NoIcon, 'This is my application’s about box. (Click to close)', NoButtonAlert);
-
- FileMenu:
- case Poll.Menu.Item of
- NewItem:
- ;
- OpenItem:
- ;
- CloseItem:
- ;
- QuitItem:
- ExitTheDemo := true;
- end
- end;
-
- MenuHilite(0); {Turn off highlighted menu}
- end;
-
-
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - }
- procedure ApplicationInitialization;
- const
- DemoWindow1 = 1;
- begin
- { Do all the application setup before you start polling for events… }
-
- {Create an Apple menu with an 'About…' item…}
- AppleMenu('About My App…');
-
- {Create the standard File and Edit menus…}
- Menu(FileMenu, 0, enabled, 'File');
- Menu(FileMenu, 1, disabled, 'New/N');
- Menu(FileMenu, 2, disabled, 'Open/O');
- Menu(FileMenu, 3, disabled, 'Close/W');
- Menu(FileMenu, 4, disabled, mDividingLine);
- Menu(FileMenu, 5, enabled, 'Quit/Q');
-
- Menu(EditMenu, 0, enabled, 'Edit');
- Menu(EditMenu, 1, disabled, 'Undo/Z');
- Menu(EditMenu, 2, disabled, mDividingLine);
- Menu(EditMenu, 3, disabled, 'Cut/X');
- Menu(EditMenu, 4, disabled, 'Copy/C');
- Menu(EditMenu, 5, disabled, 'Paste/V');
- Menu(EditMenu, 6, disabled, 'Clear');
- Menu(EditMenu, 7, disabled, mDividingLine);
- Menu(EditMenu, 8, disabled, 'Show Clipboard…');
- UpdateMenuBar;
-
-
-
- WindowOpen(DemoWindow1, 5, 40, 206, 312, 'Editing Field Tutorial', noGrowDocProc, GoAway, NotModal);
-
- { Allocate text handles for editing fields, and initialize to a null string…}
- hField1 := Str30Handle(NewStrHandle(30));
- hField2 := NewStrHandle(255);
- hField3 := NewStrHandle(255);
-
- { Set each field's text to a default value…}
- hField1^^ := 'Length limited field';
- hField2^^ := 'Single line editing field.';
- hField3^^ := 'This is a multiple-line editing field which incorporates word wrap.';
-
- { Create first field using Monaco 9pt. It is length limited to 30 characters…}
- TextFont(Monaco);
- TextSize(9);
- FieldLengthLimit(on);
- NewField(1, 10, 10, 191, 21, Handle(hField1), teBoxNoCR, teJustLeft);
- FieldLengthLimit(off);
-
- { Create second field using Geneva 9pt bold. This is a single-line field…}
- TextFont(Geneva);
- TextFace([bold]);
- NewField(2, 10, 30, 191, 42, Handle(hField2), teBoxNoCR, teJustLeft);
-
- { Create third field using Chicago 12pt. This is a multiple line editing field…}
- TextFont(systemFont);
- TextSize(12);
- TextFace([]);
- NewField(3, 10, 51, 191, 227, Handle(hField3), teBoxCR, teJustLeft);
-
- ActivateField(1, teSelectEnd); {Activate the first field with insertion point at the end of the text}
-
- NewButton(bToField, 6, 238, 95, 258, 'Write to #3', pushButProc, enabled, notSelected);
- NewButton(bFromField, 105, 238, 195, 258, 'Get from #3', pushButProc, enabled, notSelected);
- ExitTheDemo := false;
- end;
-
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - }
- begin
- {$IFC MWERKS}
- {Toolbox initialization - - Done automatically by THINK Pascal}
- InitGraf(@qd.thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- MaxApplZone;
- {$ENDC}
-
- if not InitToolsPlus(0, 1, UseColor) then
- ExitToShell;
-
- ApplicationInitialization;
-
- while not ExitTheDemo do {Main Event Loop}
- if PollSystem(Poll) then {If an event is available, process the event…}
-
- case Poll.What of
-
- doMenu:
- ProcessMenuSelection;
-
- doGoAway: {User clicked a window's close box}
- WindowClose(Poll.Window);
-
-
- doKeyDown, doAutoKey: {Typing (check for Tab and Shift/Tab)… }
- { If key-stroke is in window 1, it's a tab, and the Command, Option and Control keys were not down…}
- if (Poll.Window = 1) and (Poll.Key.Chr = TabKey) and not (Poll.Modifiers.CmdKey or Poll.Modifiers.OptionKey or Poll.Modifiers.ControlKey) then
- begin
- SaveFieldString; {Save the field's edited text as the field's string }
- Field := ActiveFieldNumber; {Determine the active field number }
- if not Poll.Modifiers.ShiftKey then {TAB: to next field… }
- Field := Field + 1 - 3 * ord(Field = 3) { Add 1. If field=3, start at 1 again. }
- else {SHIFT-TAB: to previous field… }
- Field := Field - 1 + 3 * ord(Field = 1); { Subtract 1. If field=1, start at 3. }
- ActivateField(Field, teSelectAll); {Select all the text in the newly activated field }
- end;
-
-
- doClickField: {User clicked in an inactive field…}
- begin
- CurrentWindow(1); {The following commands apply to window #1…}
- SaveFieldString; {Save the field's edited text as the field's string }
- ClickInField; {Process the click in the inactive field}
- end;
-
-
- doButton: {User clicked a button… }
- case Poll.Button.Num of
- bToField:{Write into field #3…}
- PasteIntoField(3, 'This is the replacement text pasted by the application', teReplace);
-
- bFromField: {Display contents of field #3…}
- begin
- if ActiveFieldNumber = 3 then {If user is editing field #3…}
- GetFieldString(EditString) { get the EDITED text.}
- else
- EditString := hField3^^; {Copy field's (permanent) text to EditString}
- theButton := AlertBox(noteIcon, EditString, -OkAlert);
- end
- end;
-
-
- otherwise {All other events are ignored}
- end
- end.